package com.pesilo.module.home.mvc.view.component
{
	import com.greensock.TweenMax;
	import com.pesilo.base.BaseComponent;
	import com.pesilo.module.home.ui.Starlink;
	import com.pesilo.util.Logger;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;

	public class HomeComponent extends BaseComponent
	{
		private var mc:Sprite;
		private var starlink:Starlink;
		public function HomeComponent()
		{
			super();
		}
		
		override public function initUI():void{
			mc=new Sprite();
			this.addChild(mc);
			
			starlink=new Starlink();
			mc.addChild(starlink);
			
			//初始化状态
			for(var i:uint=0;i<5;i++){
				starlink.getChildByName("line_"+i).alpha=0;
			}
		}
		
		override public function initEvent(b:Boolean=true):void{
			var i:int;
			if(b){
				for(i=0;i<=5;i++){
					starlink.getChildByName("star_"+i).addEventListener(MouseEvent.CLICK,__mouseClickHandle);
					starlink.getChildByName("star_"+i).addEventListener(MouseEvent.ROLL_OVER,__mouseRollHandle);
					starlink.getChildByName("star_"+i).addEventListener(MouseEvent.ROLL_OUT,__mouseRollHandle);
				}
			}else{
				for(i=0;i<=5;i++){
					starlink.getChildByName("star_"+i).removeEventListener(MouseEvent.CLICK,__mouseClickHandle);
					starlink.getChildByName("star_"+i).removeEventListener(MouseEvent.ROLL_OVER,__mouseRollHandle);
					starlink.getChildByName("star_"+i).removeEventListener(MouseEvent.ROLL_OUT,__mouseRollHandle);
				}
			}
		}
		
		protected function __mouseClickHandle(e:MouseEvent):void
		{
			var tid:int=int((e.currentTarget.name as String).substr(5));
			Logger.logInfo("tid:"+tid);
			
		}
		
		protected function __mouseRollHandle(e:MouseEvent):void
		{
			var i:uint=0;
			var starID:int=int((e.currentTarget.name as String).substr(5));
			switch(e.type){
				case MouseEvent.ROLL_OVER:
					TweenMax.to(e.currentTarget,0.5,{glowFilter:{color:0xFFFFFF,blurX:10,blurY:10}});
					for(i=0;i<starID;i++){
						TweenMax.to(starlink.getChildByName("line_"+i),0.5,{alpha:1});
					}
					break;
				case MouseEvent.ROLL_OUT:
					TweenMax.to(e.currentTarget,0.5,{glowFilter:{color:0xFFFFFF,blurX:3,blurY:3}});
					for(i=0;i<starID;i++){
						TweenMax.to(starlink.getChildByName("line_"+i),0.5,{alpha:0});
					}
					break;
			}
		}
		
		override public function initLocation():void{
			starlink.x=stage.stageWidth/2;
			starlink.y=stage.stageHeight/2;
		}
	}
}